
#-------------------------------------------------------------------------------
# config input&output 
#-------------------------------------------------------------------------------

OUTDIR=.\out
OUTOBJDIR=$(OUTDIR)\obj
OUTLIBDIR=$(OUTDIR)\lib
BUILDLOG=$(OUTDIR)\build.log
BINFILE=$(OUTDIR)\app.bin
ELFFILE=$(OUTDIR)\app.elf
LISFILE=$(OUTDIR)\app.lis
SYMFILE=$(OUTDIR)\app.sym
ASMFILE=$(OUTDIR)\app.s

SCATFILE=.\make\scatterApp.txt
SYMTABLE=.\make\firmware.sym

SRCDIR=.\src
LIBDIR=.\libs


#-------------------------------------------------------------------------------
# config toolchain
#-------------------------------------------------------------------------------

MAKE = make\make.exe
CC16 = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\armcc.exe --thumb
CC32 = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\armcc.exe --arm
ASM = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\asm.exe
AR = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\armar.exe
export MAKE CC16 CC32 ASM AR

LINK = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\armlink.exe
FROMELF = C:\Progra~1\ARM\RVCT\Programs\3.1\569\win_32-pentium\fromelf.exe

CFLAGS = --cpu ARM7EJ-S --littleend -O3 --remove_unneeded_entities -JC:\Progra~1\ARM\RVCT\Data\3.1\569\include\windows --fpmode=ieee_fixed --split_sections  --diag_suppress 1,1295,1296,2548 --dwarf2 --debug --no_debug_macros
#CDEFS = -D__FILE__=__MODULE__ -D__RVCT__ -DMT2503 -DMT6261
CDEFS = -D__RVCT__ -DMT2503 -DMT6261
LIBOPT = --create
export CFLAGS CDEFS LIBOPT

LNKOPT = --cpu ARM7EJ-S --map --info sizes,totals --symbols --xref --remove --pad 0x00 --datacompressor off --first LARGEPOOL_FIRST_ZI --max_veneer_passes=400 --verbose --trace p,v,t --largeregions --scatter $(SCATFILE) --libpath C:\Progra~1\ARM\RVCT\Data\3.1\569\lib

BINEDIT = appEditer.exe

time:
	@echo %date:~0,10% %time:~0,8%
	
new:prebuild compile link bin editbin time

prebuild:
	@if exist $(strip $(BUILDLOG)) \
		@del /f  $(strip $(BUILDLOG))
	@if not exist $(strip $(OUTOBJDIR)) \
		@mkdir $(strip $(OUTOBJDIR))
	@if not exist $(strip $(OUTLIBDIR)) \
		@mkdir $(strip $(OUTLIBDIR))
		
compile:
	$(MAKE) -C $(SRCDIR)	 
	
link:
	$(LINK) $(LNKOPT) $(SYMTABLE) $(SRCDIR)\cmcc_app_gfh.o $(SRCDIR)\cmcc_app_init.o $(OUTLIBDIR)\app.a --output $(ELFFILE) --symdefs $(SYMFILE) --list $(LISFILE) 2>>$(BUILDLOG)
	$(FROMELF) -c -s $(ELFFILE) >$(ASMFILE)

bin:
	$(FROMELF) --output $(BINFILE) --bin $(ELFFILE) 2>>$(BUILDLOG)
	
editbin:
	$(BINEDIT) $(BINFILE)
	
clean:
	@if exist $(strip $(OUTDIR)) \
		@del /f /q $(strip $(OUTDIR))\*
	@if exist $(strip $(OUTOBJDIR)) \
		@del /s /q $(strip $(OUTOBJDIR))\*
	@if exist $(strip $(OUTLIBDIR)) \
		@del /s /q $(strip $(OUTLIBDIR))\*
